#include "defines.h"
#include "callBackImpl.h"
#include <string.h>

char *e_quotes [] = {
  "Any intelligent fool can make things bigger, more complex, and more violent.\
It takes a touch of genius -- and a lot of courage --\
to move in the opposite direction.",
  "Imagination is more important than knowledge.",
  "Gravitation is not responsible for people falling in love.",
  "I want to know God's thoughts; the rest are details.",
  "The hardest thing in the world to understand is the income tax.",
  "Reality is merely an illusion, albeit a very persistent one.",
  "The only real valuable thing is intuition.",
  "A person starts to live when he can live outside himself.",
  "I am convinced that He (God) does not play dice.",
  "God is subtle but he is not malicious.",
  "Weakness of attitude becomes weakness of character.",
  "I never think of the future. It comes soon enough.",
  "The eternal mystery of the world is its comprehensibility.",
  "Sometimes one pays most for the things one gets for nothing.",
  "Science without religion is lame. Religion without science is blind.",
  "Anyone who has never made a mistake has never tried anything new.",
  "Great spirits have often encountered violent opposition from weak minds.",
  "Everything should be made as simple as possible, but not simpler.",
  "Common sense is the collection of prejudices acquired by age eighteen.",
  "Science is a wonderful thing if one does not have to earn one's living at it.",
  "The secret to creativity is knowing how to hide your sources.",
  "The only thing that interferes with my learning is my education.",
  "God does not care about our mathematical difficulties. He integrates\
empirically." ,
  "The whole of science is nothing more than a refinement of everyday thinking." ,
  "Technological progress is like an axe in the hands of a pathological criminal.",
  "Peace cannot be kept by force. It can only be achieved by understanding.",
  "The most incomprehensible thing about the world is that it is comprehensible.",
};

callBackImpl::callBackImpl(std::string &m):statMsg(m)
{
}

callBackImpl::~callBackImpl()
{
}

xret
callBackImpl::handleMessage(const char *from,const char *msg,
                                char *wdata, size_t *len)
{
  if( !strncasecmp("echo",msg, 4) ) {
    int plen = -1;
    if( strchr(msg,' ') ) {
      plen = snprintf(wdata,*len,"Echo string:%s",msg);
    } else {
      int index = (time(NULL) % (sizeof(e_quotes)/sizeof(char*)));
      plen = snprintf(wdata,*len,"Echo string:%s", e_quotes[index] );
    }
    if( *len > (size_t)plen )/*truncation*/
      *len = plen;
    return xp_OK;
  }
  return xp_FAIL;
}

xret
callBackImpl::handleBind(char *msg, size_t *len)
{
  size_t l = this->statMsg.length();
  if( 0 < l ) {
    strncpy(msg,this->statMsg.c_str(), *len);
    *len = l;
  }
  return xp_OK;
}

xret
callBackImpl::handleIq(iksparser *parser,ikspak *pak)
{
  return xp_OK;
}

xret
callBackImpl::handlePresence(iksparser *parser ,ikspak *pak)
{
  return xp_OK;
}

/*
vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=2:encoding=utf-8:textwidth=80
*/
